<?php
require_once '../include/common.php';
ignore_user_abort();
set_time_limit(0); 
$file = "cache/vip.db";
$hs_num = file_get_contents($file);
$hs= $hs_num + 1;
file_put_contents($file, $hs);






	
	$z_sql = "SELECT `id` FROM `w_user` WHERE vip>'0'";
	$z_sth = $db->query($z_sql);
	$z_num = $z_sth->rowCount();
	$num=ceil($z_num / $run_num);
	

	$now_num=($hs_num%$num)*$run_num;
	
	$vip_sql = "SELECT `id`,`vip`,`viptime` FROM `w_user` WHERE vip>'0' limit {$now_num},{$run_num}";
	$vip_sth = $db->query($vip_sql);
	$arr_vip=$vip_sth->fetchAll();
	foreach ($arr_vip as $value) {
		$viptime=$value[viptime]+$value[vip]*86400*30;
		$newtime=time();
		if($newtime>$viptime){
			$sql = "UPDATE `w_user` SET `vip`='0',`viptime`='0' WHERE id='{$value[id]}'";
			$db->exec($sql);
			$sql2="SELECT MIN(gqid) FROM `w_qq` WHERE id='{$value[id]}'";
			$gqid_sth=$db->query($sql2);
			$gqid=$gqid_sth->fetch();
			
			$sql3="DELETE FROM `w_qq` WHERE gqid!='{$gqid[0]}' AND id='{$value[id]}'";
			$db->exec($sql3);

		}
		
		
	}
echo 'ok';